﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HtmlAgilityPack;
using NowFloats.RichSnippetExtractor.MicroData;
using NowFloats.RichSnippetExtractor.MicroFormat;
using NowFloats.RichSnippetExtractor.RDFa;

namespace NowFloats.RichSnippetExtractor
{
    public class RichSnippetManager
    {
        public String Url { get; set; }
        
        public RichSnippetManager()
        {

        }

        public RichSnippetManager(String Url)
        {
            this.Url = Url;   
        }

        public float? GetAggregateRating()
        {
            float? rating;
            if (!String.IsNullOrEmpty(this.Url))
            {
                HtmlDocument document = (new HtmlWeb()).Load(this.Url);
                MicroDataRequest microDataRequest = new MicroDataRequest();
                rating = microDataRequest.GetAggregateRating(document);
                if (rating.HasValue)
                    return rating;

                MicroFormatRequest microFormatRequest = new MicroFormatRequest();
                rating = microFormatRequest.GetAggregateRatings(document);
                if (rating.HasValue)
                    return rating;

                RdfaRequest request = new RdfaRequest();
                rating = request.GetAverageRDFaRatings(document);
                if (rating.HasValue)
                    return rating;
            }
            return null;
        }

        public float? GetRating()
        {
            return null;
        }

    }
}
